package org.gunncs.actoriface;

import com.sun.spot.sensorboard.peripheral.Servo;
//import com.gunncs.actors.PongDemoActor;
//import com.gunncs.actors.SimpleNavigator;
import com.sun.spot.util.Utils;
import java.io.*;
import org.gunncs.actoriface.Robot;
import com.iaroc.irobot.*;
import com.sun.spot.sensorboard.io.*;
import org.gunncs.actoriface.*;
import org.gunncs.actoriface.*;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.LEDColor;
import java.util.*;
import com.sun.spot.sensorboard.io.*;
import com.sun.spot.sensorboard.peripheral.Servo;

/**
 * <<Class summary>>
 *
 * @author Anand Gupta &lt;&gt;
 * @version $Rev$
 */
public class SServo extends Sensor {
    public static int MAX = 180;
    private Servo device;
    private double angle;

    public SServo(IOutputPin i, double angle) {
        this(new Servo(i), angle);
    }

    public SServo(Servo s, double a) {
        device = s;
        angle = a;
        device.setPosition((float)(angle/MAX));
    }

    public void rotate(double angle) {
        turn(angle - this.angle);
        this.angle = angle;
    }

    public void turn(double a) {     //default couterclockwise
        this.angle = +a;
        device.setPosition((float)(angle/MAX));
    }

    public String getName() {
        return "Servo"; 
    }

    public int getID() {
        return 5;
    }

    public synchronized void update(Thread daemon) throws InterruptedException, IOException {
        double[] reading = new double[2];
        reading[0] = angle;
        reading[1] = (double) Simulator.time();
        setState(reading);
    }
}
